package org.queryexecutor.swing.frames.components.methods;

import java.awt.CardLayout;
import java.awt.event.ItemEvent;

import javax.swing.JComboBox;
import javax.swing.JPanel;

import org.queryexecutor.database.drivers.DatabaseDrivers;

public class ComboBoxMethods
{
	
	private static ComboBoxMethods cbMethods;
	
	private ComboBoxMethods(){}
	
	public static ComboBoxMethods getInstance()
	{
		if(cbMethods == null){
			cbMethods = new ComboBoxMethods();
		}
		return cbMethods;
	}
	
	public void dbTypesCBOnItemStateChange(ItemEvent e, JPanel panel)
	{
		JComboBox cb = (JComboBox) e.getSource();
		if(e.getStateChange() == ItemEvent.SELECTED){
			CardLayout layout = (CardLayout) panel.getLayout();
			String type = ((DatabaseDrivers)cb.getSelectedItem()).getType();
			if(type.equals("local")){
				layout.show(panel, "localFilePane");
			}else{
				layout.show(panel, "serverPane");
			}
		}
	}
}
